import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button } from "antd";
import { toJS } from 'mobx';
import { WeaLocaleProvider, WeaDialog, WeaTableEdit} from 'ecCom';
import { WeaTableNew } from "comsMobx";
import {Condition, CardCondition} from '../list/listCondition';
import {WeaScore} from '../infoHandle/WeaScore';
import {Text} from '../util/text';
const text = new Text();
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@observer
class RewardDialog extends React.Component {

    //加分项明细弹出框
    componentDidMount() {

    }
   
    reRenderColumns(columns) {
        const {store} = this.props;
        store.data = [];
        //console.log("columns", columns);
        columns.forEach((c,index) => {
            if (c.dataIndex == 'title') {
                c.render = (text, record, index) => {
                    let valueSpan = record[c.dataIndex];
                    return <span dangerouslySetInnerHTML={{ __html: valueSpan }} style={{ cursor: "pointer" }} onClick={(v) => this.onChange(v, text, record, index) }>213</span>
                }
            } else {
                c.render = function (text, record) {
                    // let valueSpan = record[c.dataIndex + "span"] !== undefined ? record[c.dataIndex + "span"] : record[c.dataIndex];
                    // let type = record.type;
                    // let name = record.name;
                    // let score = record.score;
                    // let json = record.json;
                    // return <WeaScore type={type} name={name} score={score} json={json} id={text}/>
                    // if(text == '658') {
                    //     return <WeaScore type={1} name={'加分项1'} score={5} id={text}/>
                    // }
                    // if(text == '657') {
                    //     return <WeaScore type={2} name={'加分项2'} score={9} id={text}/>
                    // }
                    // if(text == '656') {
                    //     return <WeaScore type={3} name={'加分项3'} score={10} id={text}/>
                    // }
                    // if(text == '653') {
                    //     return <WeaScore type={3} name={'加分项4'} score={20} id={text}/>
                    // }
                    // if(text == '652') {
                    //     return <WeaScore type={2} name={'加分项5'} score={3} id={text}/>
                    // }
                    // if(text == '651') {
                    //     return <WeaScore type={1} name={'加分项6'} score={10} id={text}/>
                    // }
                    // return <WeaScore type={2} name={'加分项。。。'} score={2} id={text}/>
                    let type = JSON.parse(record.idspan).type;
                    let name = JSON.parse(record.idspan).name;
                    let score = JSON.parse(record.idspan).score;
                    let isEdit = JSON.parse(record.idspan).isEdit;
                    let json = JSON.parse(record.idspan).cascaderJson;
                    let jsonObject = (new Function("return " + json))();
                    if (type == '0') {           //type：0 表示只有加分项，1表示选择刊型，2表示选择栏目
                        store.data.push({ 'type': '0', 'id': text, 'j_type': '', 'j_column': '', 'score': '' });
                    }
                    if (type == '1') {
                        store.data.push({ 'type': '1', 'id': text, 'j_type': '', 'j_column': '', 'score': '' });
                    }
                    if (type == '2') {
                        store.data.push({ 'type': '2', 'id': text, 'j_type': '', 'j_column': '', 'score': '' });
                    }
                    return <WeaScore ecId={`${this && this.props && this.props.ecId || ''}_WeaScore@6rszde@${index}`} type={type} name={name} score={score} json={jsonObject} id={text} store={store} isEdit={isEdit}/>
                }
            }
        })
        return columns;
    }

    onRowSelect = (sRowKeys, rows, dataIndex, selectedDatas) => {
        const { store} = this.props;
        store.selectedDatas = rows;
    }

    getColumns(columns) {
        const {store} = this.props;
        columns && columns.forEach((col) => {
            if (col.dataIndex === 'title') {
                col.com = [{
                    type: 'CUSTOM',
                    key: 'title',
                    render: (text, record, index, onEdit) => {
                        let json = toJS(record.cascaderJson);
                        //let jsonObject = (new Function("return " + json))();
                        return <WeaScore ecId={`${this && this.props && this.props.ecId || ''}_WeaScore@gkez2l@${col.dataIndex}`} store={store} type={record.type} name={record.name} score={record.score} json={json} store={store} id={record.id} values={record.values} isEdit={record.isEdit}/>
                        //return <WeaScore type={record.type} name={record.name} score={record.score} json={record.json} />
                    }
                }]
            }
        })
        return columns;
    }

    render() {
        const { store, store: {status, setState, saveReward,close, columns, datas,selectedRowKeys} } = this.props;
        const {visible} = status;
        return (
            <div>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@33rdkm`}
                    icon="icon-coms-government"
                    iconBgcolor='#f14a2d'
                    title={text.SCORELIST}
                    visible={visible}
                    style={{ width: 800, height: 500 }}
                    onCancel={() => close() }
                    buttons={[(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@1ecevg@saveReward`} type="primary" onClick={() => saveReward() }>{text.SURE}</Button>),
                        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@n9qc68@close`} type="ghost" onClick ={() => close() }>{text.CANCEL}</Button>)
                    ]}
                    >
                    <div>
                        <WeaTableEdit ecId={`${this && this.props && this.props.ecId || ''}_WeaTableEdit@mk8sa9`}
                            ref={el => { store.tableEdit = el } }
                            showTitle={false}
                            columns={this.getColumns(toJS(columns)) }
                            datas={toJS(datas) }
                            onRowSelect={this.onRowSelect}
                            selectedRowKeys={selectedRowKeys}
                            />
                    </div>
                </WeaDialog>
            </div>
        )
    }

}

export {RewardDialog};